package com.googlecode.kipler.transformations;

import java.util.LinkedHashSet;
import java.util.Set;

import com.googlecode.kipler.syntax.formula.BooleanFormula;
import com.googlecode.kipler.syntax.formula.ConceptAssertion;
import com.googlecode.kipler.syntax.formula.ConceptDefinition;
import com.googlecode.kipler.syntax.formula.FormulaVisitor;
import com.googlecode.kipler.syntax.formula.LTLBinaryFormula;
import com.googlecode.kipler.syntax.formula.LTLUnaryFormula;
import com.googlecode.kipler.syntax.formula.ObjectRoleAssertion;
import com.googlecode.kipler.syntax.formula.RoleAssertion;
import com.googlecode.kipler.syntax.formula.RoleInclusion;
import com.googlecode.kipler.syntax.formula.SameIndividualAssertion;


/**
 * 
 * @author İnanç Seylan
 * 
 */
public class IndividualCollectionFromFormulaVisitor implements FormulaVisitor {
	private Set<String> oldIndividualSet = new LinkedHashSet<String>();

	public Set<String> getOldIndividualSet() {
		return oldIndividualSet;
	}

	public void visitBooleanFormula(BooleanFormula be) {
		be.getLhs().accept(this);
		be.getRhs().accept(this);
	}

	public void visitConceptAssertion(ConceptAssertion ca) {
		oldIndividualSet.add(ca.getName());
		NominalCollectionFromDescriptionVisitor visitor = new NominalCollectionFromDescriptionVisitor();
		ca.getConcept().accept(visitor);
		oldIndividualSet.addAll(visitor.getNominalSet());
	}

	public void visitConceptDefinition(ConceptDefinition cd) {
		NominalCollectionFromDescriptionVisitor visitor = new NominalCollectionFromDescriptionVisitor();
		cd.getLhs().accept(visitor);
		oldIndividualSet.addAll(visitor.getNominalSet());
		visitor = new NominalCollectionFromDescriptionVisitor();
		cd.getRhs().accept(visitor);
		oldIndividualSet.addAll(visitor.getNominalSet());
	}

	public void visitObjectRoleAssertion(ObjectRoleAssertion ra) {
		oldIndividualSet.add(ra.getOwner());
		oldIndividualSet.add(ra.getFiller());
	}

	public void visitSameIndividualAssertion(SameIndividualAssertion ia) {
		oldIndividualSet.add(ia.getLhs());
		oldIndividualSet.add(ia.getRhs());
	}

	public void visitRoleAssertion(RoleAssertion ra) {
		// nothing to do
	}

	public void visitRoleInclusion(RoleInclusion ri) {
		// nothing to do
	}

	@Override
	public void visitLTLUnaryFormula(LTLUnaryFormula unFor) {
		unFor.getOperand().accept(this);
	}
	
	@Override
	public void visitLTLBinaryFormula(LTLBinaryFormula binFor) {
		binFor.getLhs().accept(this);
		binFor.getRhs().accept(this);
	}

}
